package com.spirng.leetcode.day10;

public class Test416 {
    public boolean canPartition(int[] nums) {
        int sum=0;
        for (int i = 0; i < nums.length; i++) {
            sum+=nums[i];
        }
        int target=sum/2;
        if(sum % 2 != 0) return false;
        int [] dp=new int[target+1];
        for (int i = 0; i < nums.length; i++) {
            for (int j =target; j >= nums[i]; j--) {
                dp[j]=Math.max(dp[j],dp[j-nums[i]]+nums[i] );
            }
        }
        if(dp[target]==target){
            return true;
        }else {
            return false;
        }
    }
}
